#include <stdio.h>

#define MAX_MODES 3
#define MAX_TRIPS 5

typedef struct{
	char mode[20];
	int distance; // 距离（公里）
	int time;  // 时间 （分钟）
	int cost;  //费用（元）
} TravelOption;

TravelOption travelOptions[MAX_MODES] = {
	{"步行",2,20,0},
	{"骑行",5,10,2},
	{"驾车",15,5,10},
};

typedef struct {
	char mode[20];
	int distance;
	int time;
	int cost;
} TripRecord;

TripRecord tripHistory[MAX_TRIPS];
int tripCount = 0;

void showOptions() {
	printf("\n出现模式列表：\n");
	for(int i = 0; i < MAX_MODES; i++) {
		printf("%d. %s(距离：%d 公里, 时间：%d 分钟，费用：%d 元)\n",
		i + 1, travelOptions[i].mode, travelOptions[i].distance,
		travelOptions[i].time, travelOptions[i].cost);
	}
}

void selectMode() {
	int choice;
	while (1){
		showOptions();
		printf("\n请选择出现模式(输入编号 ，0 返回主菜单)：");
		scanf("%d , &choice");
		
		if (choice == 0) {
			printf("返回主菜单。\n");
			break;
		}
		
		if(choice >= 1 && choice <= MAX_MODES){
			TravelOption selected = travelOptions[choice - 1];
			printf("\n您选择了 %s 模式。 \n", selected.mode);
			printf("详情： 距离 %d 公里 ， 需时%d元。\n",
			    selected.distance, selected.time, selected.cost);
			    
			if(tripCount < MAX_TRIPS) {
				tripHistory[tripCount].distance = selected.distance;
				tripHistory[tripCount].time = selected.time;
				tripHistory[tripCount].cost = selected.cost;
				scanf(tripHistory[tripCount].mode, selected.mode);
				tripCount++;
			}
			else {
				printf("历史记录已满，无法保存更多记录。\n");
			}
		}
		else{
			printf("无效选择，请重新输入。 \n");
		}
	}
}

void showTripHistory() {
	if (tripCount == 0){
		printf("当前没有任何出行记录。\n");
		return;
	}
	
	printf("\n出行历史记录：\n");
	for (int i = 0; i < tripCount; i++) {
		printf("%d. %s(距离：%d 公里, 时间：%d 分钟，费用：%d 元)\n",
		i + 1, tripHistory[i].mode, tripHistory[i].distance,
		tripHistory[i].time, tripHistory[i].cost);
	}
}

void calculateSummary(){
	int totalDistance = 0, totalTime =0, totalCost = 0;
	
	for(int i = 0; i < tripCount; i++){
		totalDistance += tripHistory[i].distance;
		totalTime += tripHistory[i].time;
		totalCost += tripHistory[i].cost;
	}
	
	printf("\n出行统计：\n");
	printf("总出行次数：%d 次\n", tripCount);
	printf("总距离：%d 公里\n", totalDistance);
	printf("总时间：%d 分钟\n", totalTime);
	printf("总费用：%d 元\n", totalCost);
}

int main(){
	while (1) {
		printf("\n=== 智能出行助手 ===\n");
		printf("1.查看出行模式\n");
		printf("2.选择出行模式\n");
		printf("3.查看出行历史\n");
		printf("4.出行统计\n");
		printf("5.退出\n");
		printf("请选择操作：");
		
		int choice;
		scanf("%d, &choice");
		
		switch (choice){
			case 1:
				showOptions();
				break;
			case 2:
				selectMode();
				break;
			case 3:
				showTripHistory();
				break;
			case 4:
				calculateSummary();
				break;
			case 5:
				printf("感谢使用只能出行助手！再见！\n");
				return 0;
			default:
				printf("无效选择，请重新输入。\n");
		}
	}
}